METHOD:  Function::toString

Function.toString ()

The toString method returns a string which represents the source code of a function. This over-rides the Object.toString method. There are times when a function needs to be represented as a string, and the toString method is automatically called to do that. In this next example, the document.write statement requires the function Car to be represented as a string, so JavaScript automatically calls the toString method to produce the following output:

Code:
function car(make, model, year)
{this.make = make, this.model = model, this.year = year}
document.write(car)

Output:
function car(make, model, year) {this.make = make, this.model = model, this.year = year

With the built-in Function object the toString method would produce the following string: function Function() { [native code] }.

Copyright 2000 by Infinite Software Solutions, Inc.
Trademark Information